<?php

namespace app\admin\model\zhongzhuan\feiyu;

use think\Model;


class Feiyutoec extends Model
{

    

    

    // 表名
    protected $name = 'ec_aiuser_to_ecuser_feiyu';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'status_text',
        'label_laiyuan_biaoji_status_text',
        'starttime_text'
    ];
    
    
    public function getYixiangList(){
        return YixiangModel::cache(true,300)->column('yixiang_value,yixiang_txt');
    }
    

    
    public function getStatusList()
    {
        return ['0' => __('Status 0'), '1' => __('Status 1'), '2' => __('Status 2')];
    }
    
    public function getLabelLaiyuanBiaojiStatusList()
    {
        return ['0' => __('label_laiyuan_biaoji_status 0'), '1' => __('label_laiyuan_biaoji_status 1')];
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }
    
    public function getLabelLaiyuanBiaojiStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['label_laiyuan_biaoji_status']) ? $data['label_laiyuan_biaoji_status'] : '');
        $list = $this->getLabelLaiyuanBiaojiStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStarttimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['starttime']) ? $data['starttime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setStarttimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }
    
    
    /**
     * 关联客户表获取客户昵称
     * @return \think\model\relation\BelongsTo
     */
    public function userinfo()
    {
        return $this->belongsTo('app\admin\model\zhongzhuan\ec\Ecuser', 'ecid','id',[],'LEFT')->setEagerlyType(0);
    }
    
    
    /**
     * 关联客户表获取客户昵称
     * @return \think\model\relation\BelongsTo
     */
    public function byinfo()
    {
        return $this->belongsTo('app\admin\model\zhongzhuan\baiying\Byaitaskphone', 'byid','id',[],'LEFT')->setEagerlyType(0);
    }
    
    /**
     * 关联客户表获取客户昵称
     * @return \think\model\relation\BelongsTo
     */
    public function calljob()
    {
        return $this->belongsTo('app\admin\model\zhongzhuan\baiying\Byaitask', 'callJobId','callJobId')->setEagerlyType(0);
    }



}
